from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
import random
# 打开浏览器
driver = webdriver.Edge()
driver.maximize_window()

# 隐式等待
driver.implicitly_wait(10)

# 打开网页
driver.get("http://localhost:8080/Ascent/")
#输入账号密码
element = driver.find_element(By.NAME,"username").send_keys('ascent')
element = driver.find_element(By.NAME,"password").send_keys('ascent')
#跳转到查询页面
element = driver.find_element(By.XPATH,'//*[@id="footer"]/table/tbody/tr[2]/td[1]/input').click
element = driver.find_element(By.XPATH,'//*[@id="bannerbj2"]/div/a[3]').click
element = driver.find_element(By.XPATH,'/html/body/div[2]/div[5]/div/a[2]').click
#进行查询
#数据进行参数化
parame = {"西药", "生化药", "保健", "维生素"}
canshu = random.choice(tuple(parame))
element = driver.find_element(By.NAME,"searchValue").send_keys(canshu)
element = driver.find_element(By.XPATH,'/html/body/form/div[2]/div[4]/div[3]/table/tbody/tr[3]/td[2]/input').send_keys("西药")

time.sleep(10)